package com.devilvan.betrice;

import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.devilvan.betrice.aiqicha.vo.AiqichaOpenNoticeVo;
import com.devilvan.betrice.bilibili.vo.BilibiliReviewVo;
import com.devilvan.betrice.bilibili.vo.BilibiliVideoVo;
import com.devilvan.betrice.common.BetriceResultVo;
import com.devilvan.betrice.download.pojo.BetriceDownloadVo;
import com.devilvan.betrice.lol.controller.LolBattleController;
import com.devilvan.betrice.lol.dto.LolBattleHeaderDto;
import com.devilvan.betrice.poetry.constant.PoetryConstant;
import com.devilvan.betrice.poetry.po.PoetryHeaderPo;
import com.devilvan.betrice.pojo.EtBillBean;
import com.devilvan.betrice.pojo.Person;
import com.devilvan.betrice.proxy.impl.KdlProxy;
import com.devilvan.betrice.request.BetriceHttpBuilder;
import com.devilvan.betrice.request.pojo.BetriceHttpClient;
import com.devilvan.betrice.request.component.HttpClientComponent;
import com.devilvan.betrice.sinofinance.vo.SinaUsstockQuotesVo;
import com.devilvan.betrice.util.UCalendar;
import com.devilvan.betrice.util.UCollection;
import com.devilvan.betrice.util.UCopy;
import com.devilvan.betrice.util.UString;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLDecoder;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DataAcquisitionTestMain {
    public static final String[] TS_FINAL_ARR = new String[]{"A", "B", "C", "D"};
    public static final String TS_FINAL_STR = "GOOD";

    @Test
    public void testUpperFirst() {
        System.out.println(UString.upperFirst("success"));
        System.out.println(UString.upperCaseFirst("success"));
    }

    @Test
    public void testOptmizeInitialCapacity() {
        System.out.println(UCollection.optmizeInitialCapacity(7, UCollection.LOAD_FACTOR));
    }

    @Test
    public void testUrlQuery() {
        UrlBuilder builder = UrlBuilder.ofHttp("www.hutool.cn/aaa/bbb/?a=张三&b=%e6%9d%8e%e5%9b%9b#frag1", CharsetUtil.CHARSET_UTF_8);
        System.out.println(builder.getQuery().get("b"));
    }

    @Test
    public void testEmpty() {
        Map<String, Object> map = new HashMap<>();
        map.put("Good", "Boy");
        System.out.println(map.get("Good1"));
    }

    @Test
    public void testReduce() {
        List<Person> javaProgrammers = new ArrayList<>() {
            {
                add(new Person("Jaycob", "Java programmer", "male", 2000, 18));
                add(new Person("Brittany", "Java programmer", "female", 2371, 55));
                add(new Person("Donny", "Java programmer", "male", 3322, 25));
                add(new Person("Jonie", "Java programmer", "female", 35020, 15));
                add(new Person("Hervey", "Java programmer", "male", 2272, 25));
                add(new Person("Jaimie", "Java programmer", "female", 2057, 87));
                add(new Person("Randall", "Java programmer", "male", 3120, 99));
                add(new Person("Corrina", "Java programmer", "female", 345, 25));
                add(new Person("Dene", "Java programmer", "male", 3375, 14));
                add(new Person("Pam", "Java programmer", "female", 3426, 20));
            }
        };
        Integer reduce = javaProgrammers.stream().map(Person::getSalary).reduce(0, (x, y) -> x += y);
        System.out.println(reduce);
    }

    @Test
    public void testCatch() {
        try {
            throw new RuntimeException("Good");
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("Take it");
    }

    @Test
    public void testTimeOverOneDay() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        calendar.add(Calendar.HOUR_OF_DAY, 0);
        calendar.add(Calendar.MINUTE, +20);
        String yes = sdf.format(calendar.getTime());
        System.out.println(yes);
        int hourSub = (int) ((System.currentTimeMillis() - calendar.getTime().getTime()) / 3600000);
        System.out.println(hourSub);
    }

    @Test
    public void checkJsonParse() {
        String json = "{\"0\":true,\"rownum\":\"fc25c7b5-154f-11ee-a526-0050568808e8\",\"id\":8417,\"vrOrderNo\":\"VO2023051670110\",\"soNo\":\"\",\"orderNo\":\"TO2023051660136\",\"tranWay\":\"LCL\",\"carrierNo\":\"GYWL\",\"carrierName\":\"古羽物流\",\"tranType\":\"LAND\",\"materielDetail\":\"真石漆乳胶漆/桶/箱/36\",\"consigneeCountryCode\":\"0\",\"consigneeCountryName\":\"中国\",\"consigneeProvinceCode\":\"310000\",\"consigneeProvinceName\":\"上海市\",\"consigneeCityCode\":\"310100\",\"consigneeCityName\":\"上海城区\",\"consigneeCountyCode\":\"310115\",\"consigneeCountyName\":\"浦东新区\",\"consigneeAddressCode\":\"b89933aef29342ad9e41a5f97191c5e2\",\"consigneeContact\":\"商函\",\"shipperCountryCode\":\"0\",\"shipperCountryName\":\"中国\",\"shipperProvinceCode\":\"440000\",\"shipperProvinceName\":\"广东省\",\"shipperCityCode\":\"442000\",\"shipperCityName\":\"中山市\",\"shipperCountyCode\":\"\",\"shipperCountyName\":\"\",\"shipperAddressCode\":\"22220a4a7d4d4e3199c8909185002a43\",\"shipperAddress\":\"中山市长命水长逸路德明苑东侧约70米\",\"shipperName\":\"中山厂\",\"shipperContact\":\"黄先生\",\"shipperTel\":\"0760-5990599\",\"shipperCode\":\"ZSC\",\"consigneeCode\":\"SHSKS\",\"consigneeAddress\":\"上海三棵树火车站\",\"consigneeName\":\"上海三棵树\",\"consigneeTel\":\"18650506666\",\"stationName\":\"中山厂\",\"stationId\":\"ZSC\",\"serviceStatus\":\"DELIVERED\",\"orderType\":\"CPWL\",\"receiptQuantity\":36,\"loadQty\":36,\"createTime\":\"2023-05-16 10:58:30\",\"receiptTime\":\"2023-05-16 10:59:00\",\"loadTime\":\"2023-05-16 10:58:51\",\"def1\":\"\",\"def2\":\"\",\"def3\":\"\",\"def4\":\"\",\"def5\":\"\",\"def6\":\"\",\"def7\":\"\",\"def8\":\"\",\"consolidationNo\":\"JP2023051940209\",\"consolidationType\":\"计费集拼2023-05-19 07:12:49\",\"consolidationStatus\":\"Y\",\"costStatus\":\"已计费\",\"vrCostInfo\":\"\",\"_index\":0,\"_status\":0}";
        System.out.println(JSONObject.parseObject(json, EtBillBean.class));
    }

    // 解析网页
    @Test
    public void testListContains() {
        List<String> list = new ArrayList<>();
        list.add("XSWL");
        list.add("THWL");
        list.add("DBWL");
        list.add("CPWL");
        list.add("JSWL");
        list.add("TTWL");
        list.add("YLWL");
        list.add("CPDB");
        String s = "YLWL1";
        System.out.println(list.contains(s));
    }

    @Test
    public void testFinalArray() {
        TS_FINAL_ARR[1] = "E";
        System.out.println(Arrays.toString(TS_FINAL_ARR));
    }

    @Test
    public void testArrayListCapacity() {
        List<Integer> list = new ArrayList<>(16);
        for (int i = 0; i < 16; i++) {
            list.add(i);
        }
        list.add(90);
        System.out.println(list);
    }

    @Test
    public void testThreadLocal() {
        final ThreadLocal<String> threadLocal = new ThreadLocal<>();
        threadLocal.set("Hello, ThreadLocal!");
        new Thread(() -> {
            threadLocal.set("Hello, World!");
            System.out.println("Thread 1: " + threadLocal.get());
            threadLocal.remove();
            System.out.println("Thread 1: " + threadLocal.get());
        }).start();
        new Thread(() -> {
            threadLocal.set("Goodbye, Cruel World!");
            System.out.println("Thread 2: " + threadLocal.get());
            threadLocal.remove();
            System.out.println("Thread 2: " + threadLocal.get());
        }).start();
        try {
            Thread.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Main thread: " + threadLocal.get());
        threadLocal.remove();
    }

    @Test
    public void testHashMapLoadFactory() {
        Map<String, Object> map = new HashMap<>(2);
        map.put("good", "Van");
        System.out.println(map);
        Map<String, String> stringMap = Collections.singletonMap("good", "Van");
    }

    @Test
    public void testObjectReference() {
        BetriceResultVo<Object> betriceResultVo = new BetriceResultVo<>();
        LolBattleHeaderDto lolBattleHeaderDto = new LolBattleHeaderDto();
        lolBattleHeaderDto.setGameMode("终极魔典");
        betriceResultVo.setData(lolBattleHeaderDto);

        lolBattleHeaderDto.setGameMode("匹配");
        System.out.println(betriceResultVo);
    }

    @Test
    public void testCalendar() throws ParseException {
        Calendar calendar = Calendar.getInstance();
        String da = "2023-11-05 12:00:59";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = sdf.parse(da);
        calendar.setTime(parse);
        int i = calendar.get(Calendar.MONTH) + 1;
        System.out.println(i);
    }

    @Test
    public void streamEffective() {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            list.add(i);
        }
        long start = System.currentTimeMillis();
//        long count = list.stream().filter(f -> f % 7 == 0).count();
        long count = 0;
        for (Integer i : list) {
            if (i % 7 == 0) {
                count++;
            }
        }
        System.out.println("stream: " + count);
        System.out.println("用时：" + (System.currentTimeMillis() - start) + "ms");
    }

    @Test
    public void testOptional() {
//        BetriceDownloadVo betriceDownloadVo = new BetriceDownloadVo();
//        betriceDownloadVo.setFileName("Good");
        BetriceDownloadVo betriceDownloadVo = null;
        System.out.println(Optional.ofNullable(betriceDownloadVo).map(m -> "Good1".equals(m.getFileName())).get());
    }

    @Test
    public void parseJSON() {
//        /*<script>location.href='//sina.com';</script>*/IO.XSRV2.CallbackList['Gk1WGmwN2ZrcNRPQ']({"count":"13934","data":[
        String body = "/*<script>location.href='//sina.com';</script>*/IO.XSRV2.CallbackList['Gk1WGmwN2ZrcNRPQ']({\"count\":\"13934\",\"data\":[{\"name\":\"Apple, Inc.\",\"cname\":\"苹果公司\",\"category\":\"计算机\",\"symbol\":\"AAPL\",\"price\":\"155.00\",\"diff\":\"-0.85\",\"chg\":\"-0.55\",\"preclose\":\"155.85\",\"open\":\"156.08\",\"high\":\"156.74\",\"low\":\"154.28\",\"amplitude\":\"1.58%\",\"volume\":\"98943881\",\"mktcap\":\"2452401630000\",\"pe\":\"26.18243210\",\"market\":\"NASDAQ\",\"category_id\":\"5\"},{\"name\":\"Microsoft Corp.\",\"cname\":\"微软公司\",\"category\":\"软件\",\"symbol\":\"MSFT\",\"price\":\"279.43\",\"diff\":\"3.23\",\"chg\":\"1.17\",\"preclose\":\"276.20\",\"open\":\"278.26\",\"high\":\"283.33\",\"low\":\"276.32\",\"amplitude\":\"2.54%\",\"volume\":\"69527279\",\"mktcap\":\"2080021966706\",\"pe\":\"30.94462912\",\"market\":\"NASDAQ\",\"category_id\":\"14\"},{\"name\":\"Alphabet, Inc.\",\"cname\":\"谷歌\",\"category\":\"互联网\",\"symbol\":\"GOOG\",\"price\":\"102.46\",\"diff\":\"1.39\",\"chg\":\"1.38\",\"preclose\":\"101.07\",\"open\":\"100.84\",\"high\":\"103.49\",\"low\":\"100.75\",\"amplitude\":\"2.71%\",\"volume\":\"76139867\",\"mktcap\":\"1312205208275\",\"pe\":\"22.32243915\",\"market\":\"NASDAQ\",\"category_id\":\"41\"},{\"name\":\"Alphabet, Inc.\",\"cname\":\"谷歌A类股\",\"category\":\"媒体内容\",\"symbol\":\"GOOGL\",\"price\":\"101.62\",\"diff\":\"1.30\",\"chg\":\"1.30\",\"preclose\":\"100.32\",\"open\":\"100.26\",\"high\":\"102.83\",\"low\":\"100.10\",\"amplitude\":\"2.73%\",\"volume\":\"61028439\",\"mktcap\":\"1301447375175\",\"pe\":\"22.13943341\",\"market\":\"NASDAQ\",\"category_id\":\"702\"},{\"name\":\"Amazon.com, Inc.\",\"cname\":\"亚马逊公司\",\"category\":\"互联网\",\"symbol\":\"AMZN\",\"price\":\"98.95\",\"diff\":\"-1.09\",\"chg\":\"-1.09\",\"preclose\":\"100.04\",\"open\":\"99.79\",\"high\":\"100.66\",\"low\":\"97.45\",\"amplitude\":\"3.20%\",\"volume\":\"87300142\",\"mktcap\":\"1013966321683\",\"pe\":\"-366.48145562\",\"market\":\"NASDAQ\",\"category_id\":\"41\"},{\"name\":\"Berkshire Hathaway, Inc.\",\"cname\":\"伯克希尔-哈撒韦\",\"category\":\"保险\",\"symbol\":\"BRK.A\",\"price\":\"442765.00\",\"diff\":\"-12585.00\",\"chg\":\"-2.76\",\"preclose\":\"455350.00\",\"open\":\"453738.47\",\"high\":\"455607.56\",\"low\":\"442363.50\",\"amplitude\":\"2.91%\",\"volume\":\"5263\",\"mktcap\":\"645655419775\",\"pe\":\"-28.61717942\",\"market\":\"NYSE\",\"category_id\":\"25\"},{\"name\":\"Berkshire Hathaway, Inc.\",\"cname\":\"伯克希尔-哈撒韦B\",\"category\":\"保险\",\"symbol\":\"BRK.B\",\"price\":\"293.51\",\"diff\":\"-8.50\",\"chg\":\"-2.81\",\"preclose\":\"302.01\",\"open\":\"301.30\",\"high\":\"301.30\",\"low\":\"292.42\",\"amplitude\":\"2.94%\",\"volume\":\"15611222\",\"mktcap\":\"642009794347\",\"pe\":\"-28.46847700\",\"market\":\"NYSE\",\"category_id\":\"25\"},{\"name\":\"NVIDIA Corp.\",\"cname\":\"英伟达公司\",\"category\":\"半导体\",\"symbol\":\"NVDA\",\"price\":\"257.25\",\"diff\":\"1.84\",\"chg\":\"0.72\",\"preclose\":\"255.41\",\"open\":\"259.82\",\"high\":\"263.99\",\"low\":\"256.68\",\"amplitude\":\"2.86%\",\"volume\":\"84854298\",\"mktcap\":\"635407500000\",\"pe\":\"146.16477352\",\"market\":\"NASDAQ\",\"category_id\":\"12\"},{\"name\":\"Tesla, Inc.\",\"cname\":\"特斯拉\",\"category\":\"汽车制造\",\"symbol\":\"TSLA\",\"price\":\"180.13\",\"diff\":\"-4.00\",\"chg\":\"-2.17\",\"preclose\":\"184.13\",\"open\":\"184.51\",\"high\":\"186.22\",\"low\":\"177.33\",\"amplitude\":\"4.83%\",\"volume\":\"133196774\",\"mktcap\":\"569949834981\",\"pe\":\"44.80845914\",\"market\":\"NASDAQ\",\"category_id\":\"155\"},{\"name\":\"Meta Platforms, Inc.\",\"cname\":\"Meta Platforms, Inc.\",\"category\":null,\"symbol\":\"META\",\"price\":\"195.61\",\"diff\":\"-9.32\",\"chg\":\"-4.55\",\"preclose\":\"204.93\",\"open\":\"200.56\",\"high\":\"201.90\",\"low\":\"195.43\",\"amplitude\":\"3.16%\",\"volume\":\"50141042\",\"mktcap\":\"507146223567\",\"pe\":\"22.69257578\",\"market\":\"NASDAQ\",\"category_id\":null},{\"name\":\"Johnson & Johnson\",\"cname\":\"强生公司\",\"category\":\"制药\",\"symbol\":\"JNJ\",\"price\":\"152.38\",\"diff\":\"-1.65\",\"chg\":\"-1.07\",\"preclose\":\"154.03\",\"open\":\"154.48\",\"high\":\"154.95\",\"low\":\"152.30\",\"amplitude\":\"1.72%\",\"volume\":\"20540633\",\"mktcap\":\"475401622698\",\"pe\":\"22.31039628\",\"market\":\"NYSE\",\"category_id\":\"10\"},{\"name\":\"Taiwan Semiconductor Manufacturing Co., Ltd.\",\"cname\":\"台湾积体电路制造公司\",\"category\":\"半导体\",\"symbol\":\"TSM\",\"price\":\"89.47\",\"diff\":\"0.17\",\"chg\":\"0.19\",\"preclose\":\"89.30\",\"open\":\"89.06\",\"high\":\"90.03\",\"low\":\"89.00\",\"amplitude\":\"1.15%\",\"volume\":\"13287702\",\"mktcap\":\"464023045029\",\"pe\":\"13.65954177\",\"market\":\"NYSE\",\"category_id\":\"12\"},{\"name\":\"Visa, Inc.\",\"cname\":\"维萨卡公司\",\"category\":\"\",\"symbol\":\"V\",\"price\":\"217.39\",\"diff\":\"-0.06\",\"chg\":\"-0.03\",\"preclose\":\"217.45\",\"open\":\"214.87\",\"high\":\"218.66\",\"low\":\"214.87\",\"amplitude\":\"1.74%\",\"volume\":\"18801077\",\"mktcap\":\"447070053917\",\"pe\":\"30.19305627\",\"market\":\"NYSE\",\"category_id\":\"726\"},{\"name\":\"UnitedHealth Group, Inc.\",\"cname\":\"美国联合健康集团\",\"category\":\"卫生保健设施\",\"symbol\":\"UNH\",\"price\":\"469.50\",\"diff\":\"-2.52\",\"chg\":\"-0.53\",\"preclose\":\"472.02\",\"open\":\"471.39\",\"high\":\"472.01\",\"low\":\"466.30\",\"amplitude\":\"1.21%\",\"volume\":\"5289911\",\"mktcap\":\"437971480108\",\"pe\":\"21.85754237\",\"market\":\"NYSE\",\"category_id\":\"692\"},{\"name\":\"Exxon Mobil Corp.\",\"cname\":\"埃克森美孚公司\",\"category\":\"\",\"symbol\":\"XOM\",\"price\":\"99.84\",\"diff\":\"-1.19\",\"chg\":\"-1.18\",\"preclose\":\"101.03\",\"open\":\"100.60\",\"high\":\"101.61\",\"low\":\"99.14\",\"amplitude\":\"2.45%\",\"volume\":\"43199265\",\"mktcap\":\"406447126294\",\"pe\":\"7.49549539\",\"market\":\"NYSE\",\"category_id\":\"710\"},{\"name\":\"Walmart, Inc.\",\"cname\":\"沃尔玛公司\",\"category\":\"零售\",\"symbol\":\"WMT\",\"price\":\"139.40\",\"diff\":\"1.12\",\"chg\":\"0.81\",\"preclose\":\"138.28\",\"open\":\"138.19\",\"high\":\"139.49\",\"low\":\"137.59\",\"amplitude\":\"1.37%\",\"volume\":\"14360254\",\"mktcap\":\"375933911068\",\"pe\":\"32.49417136\",\"market\":\"NYSE\",\"category_id\":\"52\"},{\"name\":\"JPMorgan Chase & Co.\",\"cname\":\"摩根大通公司\",\"category\":\"\",\"symbol\":\"JPM\",\"price\":\"125.81\",\"diff\":\"-4.94\",\"chg\":\"-3.78\",\"preclose\":\"130.75\",\"open\":\"128.38\",\"high\":\"128.48\",\"low\":\"125.45\",\"amplitude\":\"2.32%\",\"volume\":\"38395788\",\"mktcap\":\"370303543111\",\"pe\":\"10.39752013\",\"market\":\"NYSE\",\"category_id\":\"695\"},{\"name\":\"Vanguard Total International Stock ETF\",\"cname\":\"领航 国际股票 ETF\",\"category\":\"股权\",\"symbol\":\"VXUS\",\"price\":\"52.33\",\"diff\":\"-0.52\",\"chg\":\"-0.98\",\"preclose\":\"52.85\",\"open\":\"52.52\",\"high\":\"52.58\",\"low\":\"52.13\",\"amplitude\":\"0.86%\",\"volume\":\"2269891\",\"mktcap\":\"354815641466\",\"pe\":null,\"market\":\"NASDAQ\",\"category_id\":\"145\"},{\"name\":\"Procter & Gamble Co.\",\"cname\":\"宝洁公司\",\"category\":\"\",\"symbol\":\"PG\",\"price\":\"142.93\",\"diff\":\"0.04\",\"chg\":\"0.03\",\"preclose\":\"142.89\",\"open\":\"142.50\",\"high\":\"143.39\",\"low\":\"141.53\",\"amplitude\":\"1.30%\",\"volume\":\"16018616\",\"mktcap\":\"337192448362\",\"pe\":\"24.34923262\",\"market\":\"NYSE\",\"category_id\":\"761\"},{\"name\":\"Mastercard, Inc.\",\"cname\":\"万事达卡公司\",\"category\":\"商业服务\",\"symbol\":\"MA\",\"price\":\"349.66\",\"diff\":\"1.66\",\"chg\":\"0.48\",\"preclose\":\"348.00\",\"open\":\"350.25\",\"high\":\"351.94\",\"low\":\"346.86\",\"amplitude\":\"1.46%\",\"volume\":\"8426903\",\"mktcap\":\"333310787929\",\"pe\":\"34.07992162\",\"market\":\"NYSE\",\"category_id\":\"16\"},{\"name\":\"Novo Nordisk A/S\",\"cname\":\"诺和诺德公司\",\"category\":\"制药\",\"symbol\":\"NVO\",\"price\":\"139.44\",\"diff\":\"0.55\",\"chg\":\"0.40\",\"preclose\":\"138.89\",\"open\":\"139.74\",\"high\":\"140.28\",\"low\":\"139.10\",\"amplitude\":\"0.85%\",\"volume\":\"1727231\",\"mktcap\":\"313779537152\",\"pe\":\"40.18443841\",\"market\":\"NYSE\",\"category_id\":\"10\"},{\"name\":\"Eli Lilly & Co.\",\"cname\":\"礼来公司\",\"category\":\"生物技术和制药\",\"symbol\":\"LLY\",\"price\":\"329.18\",\"diff\":\"-0.35\",\"chg\":\"-0.11\",\"preclose\":\"329.53\",\"open\":\"331.50\",\"high\":\"334.95\",\"low\":\"328.10\",\"amplitude\":\"2.08%\",\"volume\":\"8679675\",\"mktcap\":\"312818469163\",\"pe\":\"48.26685988\",\"market\":\"NYSE\",\"category_id\":\"700\"},{\"name\":\"The Home Depot, Inc.\",\"cname\":\"家得宝公司\",\"category\":\"零售\",\"symbol\":\"HD\",\"price\":\"288.39\",\"diff\":\"1.66\",\"chg\":\"0.58\",\"preclose\":\"286.73\",\"open\":\"287.82\",\"high\":\"291.95\",\"low\":\"286.26\",\"amplitude\":\"1.98%\",\"volume\":\"8341911\",\"mktcap\":\"292703033243\",\"pe\":\"17.23789734\",\"market\":\"NYSE\",\"category_id\":\"52\"},{\"name\":\"Chevron Corp.\",\"cname\":\"雪佛龙公司\",\"category\":\"油气\",\"symbol\":\"CVX\",\"price\":\"152.34\",\"diff\":\"-1.95\",\"chg\":\"-1.26\",\"preclose\":\"154.29\",\"open\":\"153.62\",\"high\":\"155.38\",\"low\":\"150.60\",\"amplitude\":\"3.10%\",\"volume\":\"33161605\",\"mktcap\":\"290462716881\",\"pe\":\"8.30643376\",\"market\":\"NYSE\",\"category_id\":\"76\"},{\"name\":\"AbbVie, Inc.\",\"cname\":\"艾伯维公司\",\"category\":\"生物技术和制药\",\"symbol\":\"ABBV\",\"price\":\"154.22\",\"diff\":\"-1.08\",\"chg\":\"-0.70\",\"preclose\":\"155.30\",\"open\":\"155.78\",\"high\":\"156.07\",\"low\":\"151.88\",\"amplitude\":\"2.70%\",\"volume\":\"42756025\",\"mktcap\":\"272876865688\",\"pe\":\"23.15615687\",\"market\":\"NYSE\",\"category_id\":\"700\"},{\"name\":\"Merck & Co., Inc.\",\"cname\":\"默沙东集团\",\"category\":\"生物技术和制药\",\"symbol\":\"MRK\",\"price\":\"104.10\",\"diff\":\"-3.24\",\"chg\":\"-3.02\",\"preclose\":\"107.34\",\"open\":\"107.15\",\"high\":\"107.31\",\"low\":\"103.48\",\"amplitude\":\"3.56%\",\"volume\":\"26402077\",\"mktcap\":\"264267471941\",\"pe\":\"18.13588896\",\"market\":\"NYSE\",\"category_id\":\"700\"},{\"name\":\"Broadcom Inc.\",\"cname\":\"博通\",\"category\":\"半导体\",\"symbol\":\"AVGO\",\"price\":\"630.97\",\"diff\":\"-5.53\",\"chg\":\"-0.87\",\"preclose\":\"636.50\",\"open\":\"636.50\",\"high\":\"639.57\",\"low\":\"627.08\",\"amplitude\":\"1.96%\",\"volume\":\"7930268\",\"mktcap\":\"263066312060\",\"pe\":\"20.58629620\",\"market\":\"NASDAQ\",\"category_id\":\"12\"},{\"name\":\"The Coca-Cola Co.\",\"cname\":\"可口可乐公司\",\"category\":\"饮料\",\"symbol\":\"KO\",\"price\":\"60.02\",\"diff\":\"-0.28\",\"chg\":\"-0.46\",\"preclose\":\"60.30\",\"open\":\"60.31\",\"high\":\"60.35\",\"low\":\"59.63\",\"amplitude\":\"1.19%\",\"volume\":\"27351210\",\"mktcap\":\"259664860551\",\"pe\":\"27.15837078\",\"market\":\"NYSE\",\"category_id\":\"74\"},{\"name\":\"ASML Holding NV\",\"cname\":\"阿斯麦公司\",\"category\":\"半导体\",\"symbol\":\"ASML\",\"price\":\"633.69\",\"diff\":\"3.13\",\"chg\":\"0.50\",\"preclose\":\"630.56\",\"open\":\"633.71\",\"high\":\"638.40\",\"low\":\"626.81\",\"amplitude\":\"1.84%\",\"volume\":\"1109009\",\"mktcap\":\"250047364820\",\"pe\":\"43.02036810\",\"market\":\"NASDAQ\",\"category_id\":\"12\"},{\"name\":\"PepsiCo, Inc.\",\"cname\":\"百事可乐公司\",\"category\":\"饮料\",\"symbol\":\"PEP\",\"price\":\"175.13\",\"diff\":\"-1.38\",\"chg\":\"-0.78\",\"preclose\":\"176.51\",\"open\":\"176.51\",\"high\":\"176.69\",\"low\":\"174.23\",\"amplitude\":\"1.39%\",\"volume\":\"8854553\",\"mktcap\":\"241198029696\",\"pe\":\"27.15193954\",\"market\":\"NYSE\",\"category_id\":\"74\"},{\"name\":\"Oracle Corp.\",\"cname\":\"甲骨文公司\",\"category\":\"软件\",\"symbol\":\"ORCL\",\"price\":\"85.26\",\"diff\":\"0.44\",\"chg\":\"0.52\",\"preclose\":\"84.82\",\"open\":\"85.00\",\"high\":\"85.98\",\"low\":\"84.61\",\"amplitude\":\"1.62%\",\"volume\":\"13066028\",\"mktcap\":\"230185124287\",\"pe\":\"27.32692476\",\"market\":\"NYSE\",\"category_id\":\"14\"},{\"name\":\"Pfizer Inc.\",\"cname\":\"辉瑞制药公司\",\"category\":\"制药\",\"symbol\":\"PFE\",\"price\":\"40.10\",\"diff\":\"-0.27\",\"chg\":\"-0.67\",\"preclose\":\"40.37\",\"open\":\"40.62\",\"high\":\"40.79\",\"low\":\"39.98\",\"amplitude\":\"1.99%\",\"volume\":\"57457580\",\"mktcap\":\"226340526304\",\"pe\":\"7.17352368\",\"market\":\"NYSE\",\"category_id\":\"10\"},{\"name\":\"Bank of America Corp.\",\"cname\":\"美国银行公司\",\"category\":\"银行\",\"symbol\":\"BAC\",\"price\":\"27.82\",\"diff\":\"-1.15\",\"chg\":\"-3.97\",\"preclose\":\"28.97\",\"open\":\"28.66\",\"high\":\"28.66\",\"low\":\"27.62\",\"amplitude\":\"3.59%\",\"volume\":\"130665479\",\"mktcap\":\"222540087258\",\"pe\":\"8.66666647\",\"market\":\"NYSE\",\"category_id\":\"61\"},{\"name\":\"Costco Wholesale Corp.\",\"cname\":\"开市客公司\",\"category\":\"\",\"symbol\":\"COST\",\"price\":\"487.05\",\"diff\":\"-0.21\",\"chg\":\"-0.04\",\"preclose\":\"487.26\",\"open\":\"489.07\",\"high\":\"489.90\",\"low\":\"481.51\",\"amplitude\":\"1.72%\",\"volume\":\"3959113\",\"mktcap\":\"215998489582\",\"pe\":\"35.73367452\",\"market\":\"NASDAQ\",\"category_id\":\"822\"},{\"name\":\"Alibaba Group Holding Ltd.\",\"cname\":\"阿里巴巴\",\"category\":null,\"symbol\":\"BABA\",\"price\":\"81.67\",\"diff\":\"-0.55\",\"chg\":\"-0.67\",\"preclose\":\"82.22\",\"open\":\"84.00\",\"high\":\"84.16\",\"low\":\"80.62\",\"amplitude\":\"4.31%\",\"volume\":\"23711126\",\"mktcap\":\"211321120262\",\"pe\":\"47.20809091\",\"market\":\"NYSE\",\"category_id\":null},{\"name\":\"Thermo Fisher Scientific, Inc.\",\"cname\":\"赛默飞世尔科技公司\",\"category\":\"\",\"symbol\":\"TMO\",\"price\":\"547.34\",\"diff\":\"-9.75\",\"chg\":\"-1.75\",\"preclose\":\"557.09\",\"open\":\"555.31\",\"high\":\"555.31\",\"low\":\"543.96\",\"amplitude\":\"2.04%\",\"volume\":\"1947916\",\"mktcap\":\"210961308696\",\"pe\":\"30.85344047\",\"market\":\"NYSE\",\"category_id\":\"738\"},{\"name\":\"Cisco Systems, Inc.\",\"cname\":\"思科系统公司\",\"category\":\"电信\",\"symbol\":\"CSCO\",\"price\":\"50.19\",\"diff\":\"0.07\",\"chg\":\"0.14\",\"preclose\":\"50.12\",\"open\":\"50.26\",\"high\":\"50.55\",\"low\":\"49.73\",\"amplitude\":\"1.63%\",\"volume\":\"47642665\",\"mktcap\":\"205569366655\",\"pe\":\"18.31751768\",\"market\":\"NASDAQ\",\"category_id\":\"30\"},{\"name\":\"AstraZeneca Plc\",\"cname\":\"阿斯利康公司\",\"category\":\"制药\",\"symbol\":\"AZN\",\"price\":\"65.61\",\"diff\":\"-0.37\",\"chg\":\"-0.56\",\"preclose\":\"65.98\",\"open\":\"65.58\",\"high\":\"65.84\",\"low\":\"65.33\",\"amplitude\":\"0.77%\",\"volume\":\"5402971\",\"mktcap\":\"203369152056\",\"pe\":\"61.89623033\",\"market\":\"NYSE\",\"category_id\":\"10\"},{\"name\":\"McDonald's Corp.\",\"cname\":\"麦当劳公司\",\"category\":\"零售\",\"symbol\":\"MCD\",\"price\":\"267.20\",\"diff\":\"-3.37\",\"chg\":\"-1.25\",\"preclose\":\"270.57\",\"open\":\"269.57\",\"high\":\"269.97\",\"low\":\"265.71\",\"amplitude\":\"1.57%\",\"volume\":\"5075191\",\"mktcap\":\"195455994237\",\"pe\":\"31.84743758\",\"market\":\"NYSE\",\"category_id\":\"52\"},{\"name\":\"Shell Plc\",\"cname\":\"荷兰皇家壳牌石油公司\",\"category\":\"\",\"symbol\":\"RDS.A\",\"price\":\"51.04\",\"diff\":\"0.00\",\"chg\":\"0.00\",\"preclose\":\"51.04\",\"open\":\"0.00\",\"high\":\"0.00\",\"low\":\"0.00\",\"amplitude\":\"1.75%\",\"volume\":\"0\",\"mktcap\":\"192700601317\",\"pe\":\"43.25423999\",\"market\":\"NYSE\",\"category_id\":\"710\"}]})";
        String prefix = "](";
        int endIndex = body.indexOf(prefix) + prefix.length();
        String content = body.substring(endIndex, body.length() - 1);
        List<SinaUsstockQuotesVo> sinaUsstockQuotesVoList = Optional.ofNullable(JSONObject.parseObject(content))
                .map(jsonObject -> jsonObject.getJSONArray("data"))
                .map(jsonArray -> jsonArray.toJavaList(SinaUsstockQuotesVo.class))
                .orElseGet(ArrayList::new);
        sinaUsstockQuotesVoList.forEach(System.out::println);
    }

    @Test
    public void testRegex() {
        String url = "https://906524.xyz/html/movie/pc/oumei_1185805611312389.html";
        String regEx = "(?<=oumei_).*?(?=.html)";
        Pattern pattern = Pattern.compile(regEx);
        //用定义好的正则表达式拆分字符串，把字符串中的数字留出来
        Matcher matcher = pattern.matcher(url);
        while (matcher.find()) {
            System.out.println(matcher.group());
        }
    }


    @Test
    public void testStr() {
        String a = "abc";
        String b = "abc";
        String c = new String("abc");
        String d = "ab" + "c";
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println(d);
        System.out.println(a == b);
        System.out.println(b == c);
        System.out.println(a == d);
    }

    @Test
    public void testComparator() {
        String s1 = "ww/100.jpg";
        String s2 = "ww/80.jpg";
        List<String> list = new ArrayList<>();
        list.add(s1);
        list.add(s2);
        list.sort(Comparator.comparingInt(o -> Integer.parseInt(o.substring(o.lastIndexOf("/") + 1, o.length() - 4))));
        list.forEach(System.out::println);
    }

    @Test
    public void testStrIndexOf() {
        String str = "https://198763.xyz/movie.php?class=oumei&id=7899670535698533";
        System.out.println(str.substring(str.lastIndexOf("id=") + "id=".length()));
    }

    @Test
    public void testSynchronized() throws InterruptedException {
        new Thread(() -> {
            method1();
        }).start();
//        TimeUnit.MILLISECONDS.sleep(500);
        new Thread(() -> {
            method2();
        }).start();
    }

    private synchronized static void method1() {
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "：method1");
    }

    private synchronized void method2() {
//        try {
//            TimeUnit.SECONDS.sleep(2);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println(Thread.currentThread().getName() + "：method2");
    }

    @Test
    public void testPredicate() {
        List<BilibiliReviewVo> bilibiliReviewVoList = new ArrayList<>();
        BilibiliReviewVo b1 = new BilibiliReviewVo();
        b1.setRpid(4455L);
        BilibiliReviewVo b2 = new BilibiliReviewVo();
        b2.setRpid(4455L);
        BilibiliReviewVo b3 = new BilibiliReviewVo();
        b3.setRpid(7788L);
        BilibiliReviewVo b4 = new BilibiliReviewVo();
        b4.setRpid(7788L);
        bilibiliReviewVoList.add(b1);
        bilibiliReviewVoList.add(b2);
        bilibiliReviewVoList.add(b3);
        bilibiliReviewVoList.add(b4);
        List<BilibiliReviewVo> reviewVoList = bilibiliReviewVoList.stream().filter(UCopy.distinctByKey(BilibiliReviewVo::getRpid)).toList();
        reviewVoList.forEach(System.out::println);
    }

    @Test
    public void testDoWhile() {
        int totalPage = -1;
        int count = 1;
        do {
        } while (count <= totalPage);
    }

    @Test
    public void testCeil() {
        Integer totalPage = (int) Math.ceil(180.0 / 10);
        System.out.println(totalPage);
    }

    @Test
    public void parseBilibiliReview() throws IOException {
        String json = IoUtil.readUtf8(FileChannel.open(Path.of("D:\\Mine\\文本文件\\bilibili-reply.json")));
        List<BilibiliReviewVo> bilibiliReviewVoList = JSONObject.parseObject(json)
                .getJSONObject("data")
                .getJSONArray("replies")
                .toJavaList(BilibiliReviewVo.class);
        System.out.println();
    }

    @Test
    public void parseBilibiliVideo() throws IOException {
        String json = IoUtil.readUtf8(FileChannel.open(Path.of("D:\\Mine\\文本文件\\bilibili-view.json")));
        BilibiliVideoVo bilibiliVideoVo = JSONObject.parseObject(json).getObject("data", BilibiliVideoVo.class);
        System.out.println(bilibiliVideoVo);
    }

    @Test
    public void parseDate() {
        Date date = new Date(System.currentTimeMillis() + 30 * 60 * 1000);
        System.out.println(date);
        Date date1 = new Date(1548333419L * 1000);
        System.out.println(date1);
    }

    @Test
    public void testConcurrentHashMap() {
        ConcurrentHashMap<String, Object> hashMap = new ConcurrentHashMap<>(2);
        hashMap.put("Van", "Do you like what you see?");
    }

    @Test
    public void testParseDoubanMovieTop250() {
        Element body = null;
        try {
            body = Jsoup.parse(new File("D:\\Mine\\Maven\\Betrice\\betrice-data-acquisition\\src\\main\\resources\\viewsource\\豆瓣250-网页源码.txt"), "UTF-8").body();
        } catch (IOException e) {
            e.printStackTrace();
        }
        assert body != null;
        Elements itemList = body.select("ol.grid_view>li>div.item");
        for (Element item : itemList) {
            Elements pic = item.select("div.pic");
            Integer movieRank = Integer.valueOf(pic.select("em").text());
            Element detailUrlPidImg = pic.select("a").first();
            String detailUrl = detailUrlPidImg.attr("href");
            Long pid = this.splitPid(detailUrl);
            String imgUrl = detailUrlPidImg.select("img").attr("src");
            Elements info = item.select("div.info");
            String name = info.select("div.hd>a>span.title").text().trim();
            String aliasName = info.select("div.hd>a>span.other").text().trim();
            Elements bd = info.select("div.bd");
            String bdp = bd.select("p:nth-child(1)").html().replaceAll("&nbsp;", "");
            String release = bdp.split("<br>")[1];
            String[] split = release.split("/");
            String releaseTime = null;
            String releaseDistrict = null;
            String kinds = null;
            for (int i = 0; i < split.length; i++) {
                if (i == 0) {
                    releaseTime = split[0].trim();
                } else if (i == 1) {
                    releaseDistrict = split[1].trim();
                } else if (i == 2) {
                    kinds = split[2].trim();
                }
            }
            Element bdStar = bd.select("div.star").first();
            String grade = bdStar.select("span:nth-child(2)").text();
            Integer commentSize = Integer.valueOf(bdStar.select("span:nth-child(4)").text().replace("人评价", ""));
            String quote = bd.select("p.quote>span.inq").text();
        }
    }

    private Long splitPid(String detailUrl) {
        String regEx = "[^0-9]+";
        Pattern pattern = Pattern.compile(regEx);
        //用定义好的正则表达式拆分字符串，把字符串中的数字留出来
        String[] cs = pattern.split(detailUrl);
        return Long.valueOf(cs[1]);
    }

    @Test
    public void testReg() {
        String regEx = "[^0-9]+";
        Pattern pattern = Pattern.compile(regEx);
        //用定义好的正则表达式拆分字符串，把字符串中的数字留出来
        Matcher matcher = pattern.matcher("https://movie.douban.com/subject/1292052/");
        String group = matcher.group();
        String[] cs = pattern.split("https://movie.douban.com/subject/1292052/");
        System.out.println(Arrays.toString(cs));
    }

    @Test
    public void parseShijing() {
        Element body = null;
        try {
            body = Jsoup.parse(new File("D:\\Mine\\Maven\\Betrice\\betrice-data-acquisition\\src\\main\\resources\\viewsource\\诗经-网页源码.txt"), "UTF-8").body();
        } catch (IOException e) {
            e.printStackTrace();
        }
        List<PoetryHeaderPo> poetryHeaderPoList = new ArrayList<>();
        Elements typeContent = body.select("div.typecont");
        for (Element s : typeContent) {
            // 主标题
            String title = s.select("div.bookMl>strong").text();
            // 作品
            Elements words = s.select("span>a");
            for (Element word : words) {
                String detailUrl = PoetryConstant.GUSHIWEN_DEFAULT_URL + word.attr("href");
                // 副标题
                String subTitle = word.text();
                PoetryHeaderPo poetryHeaderPo = new PoetryHeaderPo();
                poetryHeaderPo.setTitle(subTitle);
                poetryHeaderPo.setSubTitle(title);
                poetryHeaderPo.setAuthor(null);
                poetryHeaderPo.setDetailUrl(detailUrl);
                poetryHeaderPoList.add(poetryHeaderPo);
            }
        }
        poetryHeaderPoList.forEach(System.out::println);
    }

    @Test
    public void testSplit() {
        String str = "离骚(屈原)";
        String[] split = str.split("[(]");
        System.out.println(Arrays.toString(split));

        String str2 = "岑参〔唐代〕";
        String[] sp = str2.split("〔");
        System.out.println(Arrays.toString(sp));
    }

    @Test
    public void testReflect() {
        try {
            HttpGet httpGet = new HttpGet("www.baidu.com");
            Class<HttpRequestBase> httpRequestBaseClass = HttpRequestBase.class;
            KdlProxy kdlProxy = KdlProxy.class.getConstructor(httpRequestBaseClass).newInstance(httpGet);
            System.out.println(kdlProxy);
        } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void mapMap() {
        // 故障的节点
        Integer unAvailable = 36;
        distinct(unAvailable);
    }

    /**
     * @param unAvailable 故障的节点编号
     */
    private void distinct(Integer unAvailable) {
        // 故障前的总路由表，例如：26 : {16 : "79", 25 : "23"}
        Map<Integer, Map<Integer, String>> map = new HashMap<>();
        // 故障的节点
        Map<Integer, String> no36 = new HashMap<>();
        no36.put(26, "89");
        no36.put(35, "32");
        no36.put(37, "33");
        no36.put(46, "99");
        map.put(36, no36);
        // 需要去除故障节点 的节点
        Map<Integer, String> no26 = new HashMap<>();
        no26.put(16, "79");
        no26.put(25, "23");
        no26.put(27, "24");
        no26.put(36, "89");
        Map<Integer, String> no35 = new HashMap<>();
        no35.put(25, "88");
        no35.put(34, "31");
        no35.put(36, "32");
        no35.put(45, "98");
        Map<Integer, String> no37 = new HashMap<>();
        no37.put(27, "90");
        no37.put(36, "33");
        no37.put(38, "34");
        no37.put(47, "100");
        Map<Integer, String> no46 = new HashMap<>();
        no46.put(36, "99");
        no46.put(45, "41");
        no46.put(47, "42");
        no46.put(56, "109");
        map.put(26, no26);
        map.put(35, no35);
        map.put(37, no37);
        map.put(46, no46);
        System.out.println("节点故障前：");
        map.forEach((key, value) -> {
            System.out.println("key: " + key + ",valu: " + value);
        });
        System.out.println();

        // 获取36号字典中的 26、35、37、46
        Map<Integer, String> subUnavailableMap = map.remove(unAvailable);
        Set<Integer> subUnavailableKeySet = subUnavailableMap.keySet();

        for (Integer sub : subUnavailableKeySet) {
            Map<Integer, String> mapSub = map.get(sub);
            mapSub.remove(unAvailable);
        }
        System.out.println("节点故障后：");

        map.forEach((key, value) -> {
            System.out.println("key: " + key + ",valu: " + value);
        });
    }

    @Test
    public void testSnowFlake() {
        Snowflake snowflake = IdUtil.getSnowflake(13, 13);
        System.out.println(snowflake.nextId());
    }

    @Test
    public void testBcrypt() {
        System.out.println(new BCryptPasswordEncoder().encode("123456"));
    }

    @Test
    public void testClPage() {
        LolBattleController lolBattleController = new LolBattleController();
        List<Integer> clPage0 = new ArrayList<>();
        clPage0.add(0);
        clPage0.add(8);
        List<Integer> clPage = lolBattleController.checkClPage(clPage0);
        Integer start = clPage.get(0);
        Integer end = clPage.get(1);
        int count = start;
        while (count <= end) {
            Page<Object> objectPage = new Page<>(count, 7);
            System.out.println(objectPage.offset());
            count++;
        }
    }

    @Test
    public void testBigDecimal() {
        double win = 90;
        double play = 197;
        if (win >= 0d && play > 0d) {
            BigDecimal winRate = BigDecimal.valueOf(win / play).setScale(6, RoundingMode.CEILING);
            System.out.println(winRate);
        }
    }

    @Test
    public void offset() {
        Page<Object> objectPage = new Page<>(2, 7);
        System.out.println("" + objectPage.offset() + objectPage.getSize());
    }

    @Test
    public void calendar() {
        Date date = new Date();
        boolean passDay = UCalendar.isPassDay(date, 3);
        System.out.println(passDay);
    }

    @Test
    public void gbk2Utf8() throws UnsupportedEncodingException {
        String urlEncode = "%E5%BC%BA%E8%80%85%E4%B8%BA%E5%B0%8A%E8%A6%81%E8%AE%A9%E6%88%91";
        String decode = URLDecoder.decode(urlEncode, StandardCharsets.UTF_8);
        System.out.println(decode);
    }

    @Test
    public void testChangeDate() throws InterruptedException {
        Date date = new Date();
        System.out.println(date);
        TimeUnit.SECONDS.sleep(2);
        System.out.println(date);
    }

    @Test
    public void testParseDate() {
        String field = "2099-12-31";
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = format.parse(field);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println(date);
    }


    @Test
    public void testXinhuaNet() {
        try {
            String url = "http://www.xinhuanet.com/legal/ej.htm?page=fzzt";
            Connection connection = Jsoup.connect(url).timeout(600000).maxBodySize(0);
            Element body = connection.get().body();
            Elements select = body.select("#list > ul > li:nth-child(1) > div.txt");
            for (Element element : select) {
                System.out.println(element.toString());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void test4() {
        String json = "{\"status\":0,\"msg\":\"\",\"data\":{\"opennotice\":{\"total\":10,\"totalNum\":10,\"pageCount\":2,\"page\":1,\"size\":5,\"list\":[{\"hearingDate\":\"2022-03-29\",\"caseNo\":\"(2021)桂08民初211号\",\"caseReason\":\"金融借款合同纠纷\",\"relatedCompanies\":{\";第三人\":{\"role\":\";第三人\",\"nameArr\":[\"贵港市人民政府\"]},\"原告\":{\"role\":\"原告\",\"nameArr\":[\"贵港市交通投资建设有限公司\"]},\"被告\":{\"role\":\"被告\",\"nameArr\":[\"广西金奔腾汽车科技有限公司\",\"北京金奔腾汽车科技有限公司\"]}},\"judge\":\"莫学平\",\"court\":\"贵港市中级人民法院\",\"tribunal\":\"第十二法庭\",\"ename\":\"广西金奔腾汽车科技有限公司\",\"pureRole\":\"被告\",\"dataId\":\"3b8d777fe4d1ac960cf3c8a90c39128e\",\"dataid\":\"3b8d777fe4d1ac960cf3c8a90c39128e\",\"content\":\"-\",\"region\":\"-\",\"department\":\"-\",\"author\":\"-\",\"judgeType\":\"-\",\"detailUrl\":\"/detail/openNoticeDetail?pid\\u003d52445833250013\\u0026dataId\\u003d3b8d777fe4d1ac960cf3c8a90c39128e\",\"plaintifflist\":[\"贵港市交通投资建设有限公司\"],\"defendantlist\":[\"广西金奔腾汽车科技有限公司\",\"北京金奔腾汽车科技有限公司\"]},{\"hearingDate\":\"2022-03-29\",\"caseNo\":\"(2021)桂08民初213号\",\"caseReason\":\"金融借款合同纠纷\",\"relatedCompanies\":{\";被告\":{\"role\":\";被告\",\"nameArr\":[\"广西金奔腾汽车科技有限公司\",\"北京金奔腾汽车科技有限公司\"]},\"第三人\":{\"role\":\"第三人\",\"nameArr\":[\"贵港市人民政府\"]},\"原告\":{\"role\":\"原告\",\"nameArr\":[\"广西贵港市公共交通有限公司\"]}},\"judge\":\"莫学平\",\"court\":\"贵港市中级人民法院\",\"tribunal\":\"第十二法庭\",\"ename\":\"广西金奔腾汽车科技有限公司\",\"pureRole\":\"其他\",\"dataId\":\"fde958aaf8ae9847a2c5330981cb38d2\",\"dataid\":\"fde958aaf8ae9847a2c5330981cb38d2\",\"content\":\"-\",\"region\":\"-\",\"department\":\"-\",\"author\":\"-\",\"judgeType\":\"-\",\"detailUrl\":\"/detail/openNoticeDetail?pid\\u003d52445833250013\\u0026dataId\\u003dfde958aaf8ae9847a2c5330981cb38d2\",\"plaintifflist\":[\"广西贵港市公共交通有限公司\"],\"defendantlist\":[\"-\"]},{\"hearingDate\":\"2022-03-04\",\"caseNo\":\"(2021)桂08民初213号\",\"caseReason\":\"金融借款合同纠纷\",\"relatedCompanies\":{\";被告\":{\"role\":\";被告\",\"nameArr\":[\"广西金奔腾汽车科技有限公司\",\"北京金奔腾汽车科技有限公司\"]},\"原告\":{\"role\":\"原告\",\"nameArr\":[\"广西贵港市公共交通有限公司\"]},\"第三人\":{\"role\":\"第三人\",\"nameArr\":[\"贵港市人民政府\"]}},\"judge\":\"莫学平\",\"court\":\"贵港市中级人民法院\",\"tribunal\":\"第十二法庭\",\"ename\":\"广西金奔腾汽车科技有限公司\",\"pureRole\":\"其他\",\"dataId\":\"97f7bc6391fe4363c9455d2ec03d9f35\",\"dataid\":\"97f7bc6391fe4363c9455d2ec03d9f35\",\"content\":\"-\",\"region\":\"-\",\"department\":\"-\",\"author\":\"-\",\"judgeType\":\"-\",\"detailUrl\":\"/detail/openNoticeDetail?pid\\u003d52445833250013\\u0026dataId\\u003d97f7bc6391fe4363c9455d2ec03d9f35\",\"plaintifflist\":[\"广西贵港市公共交通有限公司\"],\"defendantlist\":[\"-\"]},{\"hearingDate\":\"2022-03-04\",\"caseNo\":\"(2021)桂08民初211号\",\"caseReason\":\"金融借款合同纠纷\",\"relatedCompanies\":{\"原告\":{\"role\":\"原告\",\"nameArr\":[\"贵港市交通投资建设有限公司\"]},\"被告\":{\"role\":\"被告\",\"nameArr\":[\"北京金奔腾汽车科技有限公司\",\"广西金奔腾汽车科技有限公司\"]},\"第三人\":{\"role\":\"第三人\",\"nameArr\":[\"贵港市人民政府\"]}},\"judge\":\"莫学平\",\"court\":\"贵港市中级人民法院\",\"tribunal\":\"第十二法庭\",\"ename\":\"广西金奔腾汽车科技有限公司\",\"pureRole\":\"被告\",\"dataId\":\"201f8ec7aa51ea5ec7f89c8aa6524a78\",\"dataid\":\"201f8ec7aa51ea5ec7f89c8aa6524a78\",\"content\":\"-\",\"region\":\"-\",\"department\":\"-\",\"author\":\"-\",\"judgeType\":\"-\",\"detailUrl\":\"/detail/openNoticeDetail?pid\\u003d52445833250013\\u0026dataId\\u003d201f8ec7aa51ea5ec7f89c8aa6524a78\",\"plaintifflist\":[\"贵港市交通投资建设有限公司\"],\"defendantlist\":[\"北京金奔腾汽车科技有限公司\",\"广西金奔腾汽车科技有限公司\"]},{\"hearingDate\":\"2021-11-29\",\"caseNo\":\"(2021)桂08民初211号\",\"caseReason\":\"金融借款合同纠纷\",\"relatedCompanies\":{\"被告\":{\"role\":\"被告\",\"nameArr\":[\"广西金奔腾汽车科技有限公司\",\"北京金奔腾汽车科技有限公司\"]},\"原告\":{\"role\":\"原告\",\"nameArr\":[\"贵港市交通投资建设有限公司\"]}},\"judge\":\"莫学平\",\"court\":\"贵港市中级人民法院\",\"tribunal\":\"第十二法庭\",\"ename\":\"广西金奔腾汽车科技有限公司\",\"pureRole\":\"被告\",\"dataId\":\"e28d98fb5d26827c63aa1f53abe00a82\",\"dataid\":\"e28d98fb5d26827c63aa1f53abe00a82\",\"content\":\"-\",\"region\":\"-\",\"department\":\"-\",\"author\":\"-\",\"judgeType\":\"-\",\"detailUrl\":\"/detail/openNoticeDetail?pid\\u003d52445833250013\\u0026dataId\\u003de28d98fb5d26827c63aa1f53abe00a82\",\"plaintifflist\":[\"贵港市交通投资建设有限公司\"],\"defendantlist\":[\"广西金奔腾汽车科技有限公司\",\"北京金奔腾汽车科技有限公司\"]}]}}}";
        JSONObject data = JSONObject.parseObject(json)
                .getJSONObject("data");
        List<AiqichaOpenNoticeVo> openNoticeVoList = data.getJSONObject("opennotice")
                .getJSONArray("list")
                .toJavaList(AiqichaOpenNoticeVo.class);
        System.out.println(openNoticeVoList);
    }

    public static void test3() {
        int len = 11;
        int dept = 5;
        for (int i = 0; i <= dept; i++) {
            for (int j = 0; j < len; j++) {
                if (j < i || j >= len - i) {
                    System.out.print(" ");
                } else {
                    System.out.print("*");
                }
            }
            System.out.println();
        }
    }

    public void testEtzbq() {
        String url = "https://www.chinapp.com/paihang/etzbq";


        //配置本地的chromediver.exe谷歌的内核
        System.setProperty("webdriver.chrome.driver", "D:\\搜狗高速下载\\chromedriver.exe");
        //设置ChromeOptions打开方式，设置headless：不弹出浏览器
        ChromeOptions options = new ChromeOptions();
        options.addArguments("headless");
        //设置好使用ChromeDriver使用
        ChromeDriver driver = new ChromeDriver(options);
        //获取要截图的地址，注：需要先获取地址哦，不然下方获取的宽度高度就会是弹窗的高和宽，而不是页面内容的高宽
        driver.get(url);
//        driver.findElement(new By.ByCssSelector("body > div.main > div.rank_top_box > div.rank_title_box > ul > li.DZ_tab.rank-vote_nav"));
        //获取页面高宽使用：return document.documentElement.scrollWidth
        Long width = (Long) ((JavascriptExecutor) driver).executeScript("return document.documentElement.scrollWidth");
        Long height = (Long) ((JavascriptExecutor) driver).executeScript("return document.documentElement.scrollHeight");
        Long windowHeight = 2150L;

        // 这里的height一定是裁剪前完整截取的图片
        driver.manage().window().setSize(new org.openqa.selenium.Dimension(width.intValue(), height.intValue()));
        //使用getScreenshotAs进行截取屏幕
        File srcFile = driver.getScreenshotAs(OutputType.FILE);
        try {
            BufferedImage image = ImageIO.read(srcFile);
            BufferedImage img = image.getSubimage(0, 260, width.intValue(), windowHeight.intValue());
            File file = new File("D:\\Mine\\杂物\\截图4.png");
            ImageIO.write(img, "png", file);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void test2() throws IOException, InterruptedException {
        //配置本地的chromediver.exe谷歌的内核
        System.setProperty("webdriver.chrome.driver", "D:\\搜狗高速下载\\chromedriver.exe");
        //设置ChromeOptions打开方式，设置headless：不弹出浏览器
        ChromeOptions options = new ChromeOptions();
        options.addArguments("headless");
        //设置好使用ChromeDriver使用
        ChromeDriver driver = new ChromeDriver(options);
        //获取要截图的地址，注：需要先获取地址哦，不然下方获取的宽度高度就会是弹窗的高和宽，而不是页面内容的高宽
        driver.get("https://www.chinapp.com/paihang/etzbq");
        // jsoup获取明细页面的ID

        HttpClientComponent httpClientComponent = new HttpClientComponent();
        String json = "{\"fid\" : 7881, \"votetype\" : \"favor\"}";
        BetriceHttpClient betriceHttpClient = BetriceHttpBuilder.create()
                .setHttpRequest(RequestMethod.POST, "https://www.chinapp.com/paihang/getList", json)
                .build();
        String response = httpClientComponent.doExecute(betriceHttpClient);
        Integer code = JSON.parseObject(response).getJSONObject("code").toJavaObject(Integer.class);
        if (400 != code) {
            driver.findElement(By.xpath("/html/body/div[5]/div[1]/div[1]/ul/li[2]")).click();
        }
//        WebDriverWait webDriverWait = new WebDriverWait(driver, 10000, 2000);
        TimeUnit.MILLISECONDS.sleep(2000);
        //获取页面高宽使用：return document.documentElement.scrollWidth
        Long width = (Long) ((JavascriptExecutor) driver).executeScript("return document.documentElement.scrollWidth");
        Long height = (Long) ((JavascriptExecutor) driver).executeScript("return document.documentElement.scrollHeight");
        Long windowHeight = 2150L;

        //设置浏览器弹窗页面的大小
//        driver.manage().window().setPosition(new org.openqa.selenium.Point(0, 0));
        // 这里的height一定是裁剪前完整截取的图片
        driver.manage().window().setSize(new org.openqa.selenium.Dimension(width.intValue(), height.intValue()));
        //使用getScreenshotAs进行截取屏幕
        File srcFile = driver.getScreenshotAs(OutputType.FILE);
        BufferedImage image = ImageIO.read(srcFile);
        BufferedImage img = image.getSubimage(0, 260, width.intValue(), windowHeight.intValue());
        File file = new File("D:\\Mine\\杂物\\截图4.png");
        ImageIO.write(img, "png", file);
//        IoUtil.copy(new FileInputStream(srcFile), new FileOutputStream("D:\\Mine\\杂物\\截图1.png"));
    }

    // height 510
    public static void test1() throws AWTException, IOException {
        System.out.println(Toolkit.getDefaultToolkit().getScreenSize());
        //创建一个robot对象
        Robot robut = new Robot();
        //获取屏幕分辨率
        Dimension dimension = new Dimension(1883, 3275);
        Point point = new Point(1000, 500);
        //打印屏幕分辨率
        //创建该分辨率的矩形对象
        Rectangle screenRect = new Rectangle(point, dimension);
        //根据这个矩形截图
        BufferedImage bufferedImage = robut.createScreenCapture(screenRect);
        //保存截图
        File file = new File("D:\\Mine\\杂物\\截图1.png");
        ImageIO.write(bufferedImage, "png", file);
    }
}
